package com.example.config;

import com.example.support.OssTemplate;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <h1>本地文件存储配置类</h1>
 * Created by hanqf on 2021/7/25 10:23.
 */

@Data
@Slf4j
@Configuration
@ConditionalOnProperty(prefix = "oss.use", name = "provider", havingValue = "local",matchIfMissing = true)
public class LocalOssConfig implements InitializingBean {
    public static String LOCAL_FILE_PATH;
    public static String DOWN_FILE_PREFIX;
    /**
     * 文件保存路径
     */
    @Value("${local.oss.filepath}")
    private String filepath;

    /**
     * 文件下载地址前缀
     */
    @Value("${local.oss.file.download.prefix}")
    private String fileDownPrefix;


    @Override
    public void afterPropertiesSet() throws Exception {
        LOCAL_FILE_PATH = filepath;
        DOWN_FILE_PREFIX = fileDownPrefix;
    }


    @Bean
    public OssTemplate ossTemplate(){
        log.info("LocalOSSTemplate");
        return new LocalOssTemplate();
    }
}
